/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddNewStaff.java
 *
 * Created on Apr 21, 2012, 2:35:51 PM
 */
package GUI;

import entities.StaffDetail;
import utilities.DateValidate;
import utilities.SimpleDateFormatter;
import utilities.StaffManage;
import utilities.ValidateInput;

/**
 *
 * @author VietLH
 */
public class AddNewStaff extends javax.swing.JDialog {

    /** Creates new form AddNewStaff */
    public AddNewStaff(java.awt.Frame parent, boolean modal, StaffManage sm, MainFunction main) {
        super(parent, modal);
        initComponents();
        this.optionMessage = new OptionMessage(this);
        this.sd = new StaffDetail();
        this.sm = sm;
        this.main = main;
        this.fDate = new SimpleDateFormatter();
        this.vi = new ValidateInput();
        hideAllError();
        dvDOB = new DateValidate(cbDayDOB, cbMonthDOB, cbYearDOB);
        dvDOJ = new DateValidate(cbDayDOJ, cbMonthDOJ, cbYearDOJ);
        this.main.setRegister(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lblFirstfName = new javax.swing.JLabel();
        lblAddress = new javax.swing.JLabel();
        lblTestName = new javax.swing.JLabel();
        btnClose = new javax.swing.JButton();
        lblTechSkill = new javax.swing.JLabel();
        lblDOB = new javax.swing.JLabel();
        lblDOJ = new javax.swing.JLabel();
        lblUsername = new javax.swing.JLabel();
        lblGender = new javax.swing.JLabel();
        lblEduQual = new javax.swing.JLabel();
        txtFirstName = new javax.swing.JTextField();
        txtLastName = new javax.swing.JTextField();
        txtAddress = new javax.swing.JTextField();
        txtPhone = new javax.swing.JTextField();
        txtEduQual = new javax.swing.JTextField();
        txtTechSkill = new javax.swing.JTextField();
        rdMale = new javax.swing.JRadioButton();
        rdFemale = new javax.swing.JRadioButton();
        btnAdd = new javax.swing.JButton();
        cbDayDOB = new javax.swing.JComboBox();
        cbMonthDOB = new javax.swing.JComboBox();
        cbYearDOB = new javax.swing.JComboBox();
        cbDayDOJ = new javax.swing.JComboBox();
        cbMonthDOJ = new javax.swing.JComboBox();
        cbYearDOJ = new javax.swing.JComboBox();
        lblPassword = new javax.swing.JLabel();
        lblConfirmPassword = new javax.swing.JLabel();
        lblInvalidPhone = new javax.swing.JLabel();
        lblPasswordNotMatch = new javax.swing.JLabel();
        lblFirstNameNull = new javax.swing.JLabel();
        lblLastNameNull = new javax.swing.JLabel();
        lblAddressNull = new javax.swing.JLabel();
        lblEduNull = new javax.swing.JLabel();
        lblTechNull = new javax.swing.JLabel();
        lblPasswordNull = new javax.swing.JLabel();
        txtPassword = new javax.swing.JPasswordField();
        txtConfirmPassword = new javax.swing.JPasswordField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblFirstfName.setText("First  Name:");

        lblAddress.setText("Address:");

        lblTestName.setText("Phone:");

        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        lblTechSkill.setText("Technical Skill:");

        lblDOB.setText("Date of birth:");

        lblDOJ.setText("Date of Join:");

        lblUsername.setText("Last Name:");

        lblGender.setText("Gender:");

        lblEduQual.setText("Education Qualification:");

        txtFirstName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFirstNameActionPerformed(evt);
            }
        });

        rdMale.setSelected(true);
        rdMale.setText("Male");

        rdFemale.setText("Female");

        btnAdd.setText("Register");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        cbDayDOB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1" }));
        cbDayDOB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDayDOBActionPerformed(evt);
            }
        });

        cbMonthDOB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1" }));
        cbMonthDOB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbMonthDOBActionPerformed(evt);
            }
        });

        cbYearDOB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1" }));
        cbYearDOB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbYearDOBActionPerformed(evt);
            }
        });

        cbDayDOJ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1" }));
        cbDayDOJ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbDayDOJActionPerformed(evt);
            }
        });

        cbMonthDOJ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1" }));
        cbMonthDOJ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbMonthDOJActionPerformed(evt);
            }
        });

        cbYearDOJ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1" }));
        cbYearDOJ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbYearDOJActionPerformed(evt);
            }
        });

        lblPassword.setText("Password:");

        lblConfirmPassword.setText("Confirm Password:");

        lblInvalidPhone.setForeground(new java.awt.Color(255, 0, 0));
        lblInvalidPhone.setText("Number only");

        lblPasswordNotMatch.setForeground(new java.awt.Color(255, 0, 0));
        lblPasswordNotMatch.setText("Password not match");

        lblFirstNameNull.setForeground(new java.awt.Color(255, 0, 0));
        lblFirstNameNull.setText("Not allow null");

        lblLastNameNull.setForeground(new java.awt.Color(255, 0, 0));
        lblLastNameNull.setText("Not allow null");

        lblAddressNull.setForeground(new java.awt.Color(255, 0, 0));
        lblAddressNull.setText("Not allow null");

        lblEduNull.setForeground(new java.awt.Color(255, 0, 0));
        lblEduNull.setText("Not allow null");

        lblTechNull.setForeground(new java.awt.Color(255, 0, 0));
        lblTechNull.setText("Not allow null");

        lblPasswordNull.setForeground(new java.awt.Color(255, 0, 0));
        lblPasswordNull.setText("Not allow null");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("Register new staff");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblFirstfName)
                                    .addComponent(lblUsername)
                                    .addComponent(lblDOB))
                                .addGap(76, 76, 76)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(cbDayDOB, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                .addGap(2, 2, 2)
                                                .addComponent(rdMale)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(rdFemale, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(cbMonthDOB, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbYearDOB, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtFirstName, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                                    .addComponent(txtLastName)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblEduQual)
                                    .addComponent(lblAddress)
                                    .addComponent(lblTechSkill)
                                    .addComponent(lblTestName)
                                    .addComponent(lblGender)
                                    .addComponent(lblDOJ)
                                    .addComponent(lblPassword)
                                    .addComponent(lblConfirmPassword))
                                .addGap(28, 28, 28)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtTechSkill, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtEduQual, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtAddress, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtConfirmPassword, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(cbDayDOJ, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(cbMonthDOJ, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(cbYearDOJ, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                                .addComponent(btnAdd)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(btnClose)))))))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblLastNameNull)
                            .addComponent(lblFirstNameNull)
                            .addComponent(lblInvalidPhone)
                            .addComponent(lblAddressNull)
                            .addComponent(lblEduNull)
                            .addComponent(lblPasswordNull)
                            .addComponent(lblTechNull)
                            .addComponent(lblPasswordNotMatch)))
                    .addComponent(jLabel1))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblFirstfName)
                    .addComponent(txtFirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFirstNameNull))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblUsername)
                    .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblLastNameNull))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDOB)
                    .addComponent(cbDayDOB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbMonthDOB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbYearDOB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblGender)
                    .addComponent(rdMale)
                    .addComponent(rdFemale))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAddress)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAddressNull))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTestName)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblInvalidPhone))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEduQual)
                    .addComponent(txtEduQual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEduNull))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTechSkill)
                    .addComponent(txtTechSkill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTechNull))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDOJ)
                    .addComponent(cbDayDOJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbMonthDOJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbYearDOJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPassword)
                    .addComponent(lblPasswordNull)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblConfirmPassword)
                            .addComponent(txtConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnAdd)
                            .addComponent(btnClose))
                        .addGap(19, 19, 19))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblPasswordNotMatch)
                        .addContainerGap())))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        addNewStaff();
    }//GEN-LAST:event_btnAddActionPerformed

    private void txtFirstNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFirstNameActionPerformed
    }//GEN-LAST:event_txtFirstNameActionPerformed

    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
        optionMessage.confirmExit();
    }//GEN-LAST:event_btnCloseActionPerformed

    private void cbDayDOBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDayDOBActionPerformed
        // TODO add your handling code here:
        dvDOB.checkValidDay();
    }//GEN-LAST:event_cbDayDOBActionPerformed

    private void cbMonthDOBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbMonthDOBActionPerformed
        // TODO add your handling code here:
        dvDOB.checkValidMonth();
    }//GEN-LAST:event_cbMonthDOBActionPerformed

    private void cbYearDOBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbYearDOBActionPerformed
        // TODO add your handling code here:
        dvDOB.changeExistYear();
    }//GEN-LAST:event_cbYearDOBActionPerformed

    private void cbDayDOJActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDayDOJActionPerformed
        // TODO add your handling code here:
        dvDOJ.checkValidDay();
    }//GEN-LAST:event_cbDayDOJActionPerformed

    private void cbMonthDOJActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbMonthDOJActionPerformed
        // TODO add your handling code here:
        dvDOJ.checkValidMonth();
    }//GEN-LAST:event_cbMonthDOJActionPerformed

    private void cbYearDOJActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbYearDOJActionPerformed
        // TODO add your handling code here:
        dvDOJ.changeExistYear();
    }//GEN-LAST:event_cbYearDOJActionPerformed
    private void addNewStaff() {
        hideAllError();
        if (checkValidForm()) {
            String DOBstr = ((cbMonthDOB.getSelectedIndex() + 1) + "/" + cbDayDOB.getSelectedIndex() + 1) + "/" + (cbYearDOB.getSelectedIndex() + 1900);
            String DOJstr = ((cbMonthDOJ.getSelectedIndex() + 1) + "/" + cbDayDOJ.getSelectedIndex() + 1) + "/" + (cbYearDOJ.getSelectedIndex() + 1900);

            sd.setStaffAddress(txtAddress.getText());
            sd.setStaffDOB(fDate.convertStringToDate(DOBstr));
            sd.setStaffDOJ(fDate.convertStringToDate(DOJstr));
            sd.setStaffEduQual(txtEduQual.getText());
            sd.setStaffFName(txtFirstName.getText());
            if (rdMale.isSelected()) {
                sd.setStaffGender(true);
            } else {
                sd.setStaffGender(false);
            }
            sd.setStaffLName(txtLastName.getText());
            sd.setStaffPhone(txtPhone.getText());
            sd.setStaffTechSkill(txtTechSkill.getText());
            char[] password = txtPassword.getPassword();
            String cPassword = "";
            for (int i = 0; i < password.length; i++) {
                cPassword += password[i];
            }
            sd.setStaffPassword(cPassword);
            if (sm.addNewStaff(sd)) {
                optionMessage.showMessage("New staff has been added successfully!");
                if (main.isLoginPass()) {
                    main.refreshReportTableView();
                }
                main.setLoginPass(true);
                main.setRegister(false);
                this.dispose();
            } else {
                optionMessage.showMessage("Fail to add new staff! Please try again later!");
            }
        }
    }

    private boolean checkValidForm() {
        boolean pass = true;
        if (vi.checkIsEmpty(txtAddress.getText())) {
            lblAddressNull.setVisible(true);
            pass = false;
        }
        if (vi.checkIsEmpty(txtEduQual.getText())) {
            lblEduNull.setVisible(true);
            pass = false;
        }
        if (vi.checkIsEmpty(txtTechSkill.getText())) {
            lblTechNull.setVisible(true);
            pass = false;
        }
        if (vi.checkIsEmpty(txtFirstName.getText())) {
            lblFirstNameNull.setVisible(true);
            pass = false;
        }
        if (vi.checkIsEmpty(txtLastName.getText())) {
            lblLastNameNull.setVisible(true);
            pass = false;
        }
        if (vi.checkIsEmpty(txtPhone.getText())) {
            lblInvalidPhone.setText("Not allow null");
            lblInvalidPhone.setVisible(true);
            pass = false;
        } else if (!vi.checkIsNumber(txtPhone.getText())) {
            lblInvalidPhone.setText("Number only");
            lblInvalidPhone.setVisible(true);
            pass = false;
        }
        if (vi.checkIsEmpty(txtPassword.getPassword())) {
            lblPasswordNull.setText("Not allow null");
            lblPasswordNull.setVisible(true);
            pass = false;
        } else if (vi.checkIsEmpty(txtConfirmPassword.getPassword())) {
            lblPasswordNotMatch.setText("Not allow empty");
            lblPasswordNotMatch.setVisible(true);
            pass = false;
        } else if (vi.isExistSpecialCharacter(txtPassword.getPassword())) {
            lblPasswordNull.setText("Not allow special characters");
            lblPasswordNull.setVisible(true);
            pass = false;
        } else if (vi.isExistSpecialCharacter(txtConfirmPassword.getPassword())) {
            lblPasswordNotMatch.setText("Not allow special characters");
            lblPasswordNotMatch.setVisible(true);
            pass = false;
        } else {
            if (!vi.checkMatchPassword(txtPassword.getPassword(), txtConfirmPassword.getPassword())) {
                lblPasswordNull.setText("Password not match");
                lblPasswordNull.setVisible(true);
                pass = false;
            }
        }
        return pass;
    }

    private void hideAllError() {
        this.lblAddressNull.setVisible(false);
        this.lblPasswordNotMatch.setVisible(false);
        this.lblFirstNameNull.setVisible(false);
        this.lblInvalidPhone.setVisible(false);
        this.lblLastNameNull.setVisible(false);
        this.lblEduNull.setVisible(false);
        this.lblTechNull.setVisible(false);
        this.lblPasswordNull.setVisible(false);
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(AddNewStaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(AddNewStaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(AddNewStaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(AddNewStaff.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /* Create and display the dialog */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                AddNewStaff dialog = new AddNewStaff(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnClose;
    private javax.swing.JComboBox cbDayDOB;
    private javax.swing.JComboBox cbDayDOJ;
    private javax.swing.JComboBox cbMonthDOB;
    private javax.swing.JComboBox cbMonthDOJ;
    private javax.swing.JComboBox cbYearDOB;
    private javax.swing.JComboBox cbYearDOJ;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblAddressNull;
    private javax.swing.JLabel lblConfirmPassword;
    private javax.swing.JLabel lblDOB;
    private javax.swing.JLabel lblDOJ;
    private javax.swing.JLabel lblEduNull;
    private javax.swing.JLabel lblEduQual;
    private javax.swing.JLabel lblFirstNameNull;
    private javax.swing.JLabel lblFirstfName;
    private javax.swing.JLabel lblGender;
    private javax.swing.JLabel lblInvalidPhone;
    private javax.swing.JLabel lblLastNameNull;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblPasswordNotMatch;
    private javax.swing.JLabel lblPasswordNull;
    private javax.swing.JLabel lblTechNull;
    private javax.swing.JLabel lblTechSkill;
    private javax.swing.JLabel lblTestName;
    private javax.swing.JLabel lblUsername;
    private javax.swing.JRadioButton rdFemale;
    private javax.swing.JRadioButton rdMale;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JPasswordField txtConfirmPassword;
    private javax.swing.JTextField txtEduQual;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtTechSkill;
    // End of variables declaration//GEN-END:variables
    private DateValidate dvDOB = new DateValidate();
    private DateValidate dvDOJ = new DateValidate();
    private OptionMessage optionMessage;
    private StaffDetail sd;
    private StaffManage sm;
    private MainFunction main;
    private SimpleDateFormatter fDate;
    private ValidateInput vi;
}
